const events = require("events");
const EventEmitter = events.EventEmitter;

function Dog(dogName , energy) {
    this.dogName = dogName;
    this.energy = energy;
    console.log(EventEmitter.call(this));
    
    this.on("bark" , () => {
        if(this.energy > 0) {
            console.log("dog is barking, energy is" + this.energy);
        } else {
            process.exit();
        }
    })
    console.log(this);
}

Dog.prototype = EventEmitter.prototype;

let dog = new Dog("taidy" , 5);
console.log(dog);
dog.on("bark" , () => {
    console.log("dog is barking");
});
dog.emit("bark");